#!/bin/zsh

set -e

version=$(cat VERSION)

mkdir -p RunZ
cp * RunZ -r 2>/dev/null || true

cd RunZ || exit 1

cp /mnt/c/mine/app/AutoHotkey/AutoHotkeyU32.exe RunZ.exe
rm -f build
rm -f Core/*.lnk
rm -f Core/Plugins.ahk
rm -f Conf/RunZ.ini
rm -f Conf/RunZ.auto.ini
rm -f Conf/SearchFileList.txt
rm -f Conf/UserFunctionsAuto.txt
rm -f Conf/UserFunctionsAuto.txt.bak
rm -f Conf/UserFileList.txt
rm -rf RunZ
rm -rf Doc/.git
rm -rf Doc/Icons
rm -rf Doc/Images
rm -f **/*64.dll

echo -e "历史版本详见 Releases · goreliu/runz · GitHub" > Doc/更新历史.md.new
echo "https://github.com/goreliu/runz/releases" >> Doc/更新历史.md.new
echo  >> Doc/更新历史.md.new
cat Doc/更新历史.md >> Doc/更新历史.md.new

for i (Doc/*.md*) {
    sed -i "1s/^/\xEF\xBB\xBF/g" $i
    # unix2dos $i
    sed -i 's/$/\r/' $i
}

mv Doc/更新历史.md.new Doc/更新历史.md
mv Doc/Home.md Doc/介绍.md
cp Doc/更新历史.md ~/tmp/RunZ\ 更新历史.txt

cd ..
a RunZ-$version.7z RunZ

# 64 位版本

cd RunZ
cp /mnt/c/mine/app/AutoHotkey/AutoHotkeyU64.exe RunZ.exe
rm -f Lib/Reserved/quricol32.dll
cp ../Lib/Reserved/quricol64.dll Lib/Reserved/quricol64.dll
rm -f Lib/TCMatch/tcmatch.dll
cp ../Lib/TCMatch/tcmatch64.dll Lib/TCMatch/tcmatch64.dll
sed -i 's/tcmatch.dll/tcmatch64.dll/g' Conf/RunZ.ini.help.txt

cd ..
a RunZ-x86_64-$version.7z RunZ

mv RunZ-$version.7z ~/tmp
mv RunZ-x86_64-$version.7z ~/tmp
rm -rf RunZ
